#include <iostream>
using namespace std;
#include <algorithm>
#define MAXN 101
int fa[MAXN];
int find(int a){
    return fa[a] == a? a : fa[a] = find(fa[a]);
}
struct edge{
    int a, b, w;
    bool operator<(const edge &y)const{
        return w < y.w;
    }
}e[MAXN*MAXN];
int main() {
    int N;
    cin >> N;
    for(int i=1; i<=N; ++i) fa[i] = i;
    int m=0;
    for(int i=1; i<=N; ++i)
        for(int j=1; j<=N; ++j){
            int tmp;
            cin >> tmp;
            if(i >= j) continue;
            ++m;
            e[m].w = tmp;
            e[m].a = i; e[m].b = j;
        }

    sort(e+1, e+1+m);

    int ans = 0;
    for(int i=1; i<=m; ++i){
        if(find(e[i].a) == find(e[i].b)) continue;
        fa[find(e[i].a)] = find(e[i].b);
        ans += e[i].w;
    }
    cout << ans;
    return 0;
}
